package com.medical.system.service.impl;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.medical.system.converter.LoginInforConverter;
import com.medical.system.mapper.SysLoginInforMapper;
import com.medical.system.model.dto.LoginInforDTO;
import com.medical.system.model.entity.SysLoginInfor;
import com.medical.system.model.vo.LoginInforVO;
import com.medical.system.service.SysLoginInforService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RequiredArgsConstructor
@Service
public class SysLoginInforServiceImpl extends ServiceImpl<SysLoginInforMapper, SysLoginInfor> implements SysLoginInforService {

    private final LoginInforConverter loginInforConverter;



    @Override
    public boolean saveLoginInfor(LoginInforDTO loginInforDTO) {
        SysLoginInfor sysLoginInfor = loginInforConverter.dto2entity(loginInforDTO);
        return save(sysLoginInfor);
    }

    @Override
    public boolean deleteLoginInfors(String idsStr) {
        Assert.isTrue(StrUtil.isNotBlank(idsStr), "删除数据为空");
        List<Long> ids = Arrays.asList(idsStr.split(","))
                .stream().map(id -> Long.parseLong(id))
                .collect(Collectors.toList());
        return removeByIds(ids);
    }

    @Override
    public LoginInforVO getLoginInforDetail(Long id) {
        return loginInforConverter.entity2VO(getById(id));
    }
}
